#-------------------------------------------------------------------------------
# Name:        模块1
# Purpose:
#
# Author:      Administrator
#
# Created:     16/07/2024
# Copyright:   (c) Administrator 2024
# Licence:     <your licence>
#-------------------------------------------------------------------------------
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import serialization
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_OAEP
from base64 import b64decode
import base64
import binascii
from Crypto.Cipher import PKCS1_v1_5

if __name__ == '__main__':
    with open('private', 'rb') as f:
        private_key = RSA.import_key(f.read())

    with open('public', 'rb') as f:
        public_key = RSA.import_key(f.read())

    message = b'automain.st("",1,1)'

    cipher_rsa = PKCS1_OAEP.new(public_key)
    encrypted_message = cipher_rsa.encrypt(message)

    encrypted_data_base64 = base64.b64encode(encrypted_message).decode('utf-8')

    #encrypted_data_base64 = "X061X735vlnOo9BGUJL7aLjwiOeb2gSCM0o6UNaH6qkazhvUatAjeC5+afdvAwNWCTOS7uiSp4SKOmmmm16QeC5wXDWmtX8ZFPH1l+LQaoJCNv0t0jRJmKVYfk91+vXmotR4eSvDPaZov+xtsOZ79JZlHv4I0dQBF4jacGmiGTfoHB8BwfXfeGG69fSLtp8LQ09K8fk1NmTdIP3dLeskjE0xj6i+6L2UqLgwk3wtaO6WvUfF/Ug1CO1CvLPc90MppKu/CfnA+fvQ8TWPn1vT9JA+WXjmMGl+hzOEG3U7JoVAaEiex1oUZut3ffNkxTn8UOVYRFdFCBgiE14utFAfbg=="

    print("Encrypted message:", encrypted_data_base64)

    encrypted_data = base64.b64decode(encrypted_data_base64)

    cipher_rsa = PKCS1_OAEP.new(private_key)
    decrypted_message = cipher_rsa.decrypt(encrypted_data)

    print("Decrypted message:", decrypted_message)

